import 'package:easy_chat_app/commons/GlobalStatus.dart';
import 'package:easy_chat_app/commons/utils/PlatformUtils.dart';
import 'package:easy_chat_app/mobile/page/MobileLaunchScreenPage.dart';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:provider/provider.dart';

import 'commons/utils/RouteUtils.dart';

void main() {
  runApp(const App());
}

class App extends StatefulWidget {
  const App({super.key});

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  final Logger _logger = Logger();

  @override
  Widget build(BuildContext context) {
    _logger.i("platform: ${PlatformUtils.isDesktop()}");
    if (PlatformUtils.isDesktop()) {
      return MultiProvider(
        providers: [
          ChangeNotifierProvider(create: (context) {
            return GlobalStatus.instance;
          }),
          ChangeNotifierProvider(create: (context) {
            return AppUserDetailChangeNotifier();
          }),
        ],
        builder: (context, child) {
          return child!;
        },
        child: MaterialApp(
          title: 'EasyChat',
          navigatorKey: RouteUtils.navigatorKey,
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
            useMaterial3: true,
          ),
          home: const LaunchScreenPage(),
          onGenerateRoute: RouteUtils.onGenerateRoute,
        ),
      );
    } else {
      return MultiProvider(
        providers: [
          ChangeNotifierProvider(create: (context) {
            return GlobalStatus.instance;
          }),
          ChangeNotifierProvider(create: (context) {
            return AppUserDetailChangeNotifier();
          }),
        ],
        builder: (context, child) {
          return child!;
        },
        child: MaterialApp(
          title: 'EasyChat',
          navigatorKey: RouteUtils.navigatorKey,
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
            useMaterial3: true,
          ),
          home: const LaunchScreenPage(),
          onGenerateRoute: RouteUtils.onGenerateRoute,
        ),
      );
    }
  }
}
